/**
 * 
 */
package client.gui.panels;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

import controllers.ControllerIF;
import controllers.ExecutionPanelController;
import entities.Ticket;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

/**
 * @author Vodi
 *
 */
public class ExecutionPanel extends JPanel implements PanelIF, ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * the execution panel controller
	 */
	private ExecutionPanelController executionPanelController;
	
	/**
	 * Structure holding all the data executor into the ticket 
	 */
	private Ticket ticket;
	
	private JButton okButton;
	
	public ExecutionPanel(Ticket ticket) {
		this.ticket = ticket;
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		add(Box.createVerticalStrut(20));
		
		JPanel promptPanel = new JPanel();
		add(promptPanel);
		promptPanel.setLayout(new BoxLayout(promptPanel, BoxLayout.X_AXIS));
		
		JLabel datePromptLabel = new JLabel("Execution stage due date: ");
		promptPanel.add(datePromptLabel);
		
		JLabel dateLabel = new JLabel(ticket.getExecutionStage().getDurationDate());
		promptPanel.add(dateLabel);
		
		add(Box.createVerticalStrut(20));
		
		JPanel actionPanel = new JPanel();
		add(actionPanel);
		actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.X_AXIS));
		
		JLabel promptLabel = new JLabel("By clicking OK you confirm that the requested change has  been completed.");
		actionPanel.add(promptLabel);
		
		add(Box.createVerticalStrut(20));
		
		JPanel panel = new JPanel();
		add(panel);
		panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
		
		Component horizontalGlue = Box.createHorizontalGlue();
		panel.add(horizontalGlue);
		
		okButton = new JButton("OK");
		okButton.setEnabled(false);
		okButton.addActionListener(this);
		panel.add(okButton);
		
		panel.add(Box.createHorizontalStrut(20));
		
		add(Box.createVerticalStrut(20));
	}

	/* (non-Javadoc)
	 * @see client.gui.panels.PanelIF#setController(controllers.ControllerIF)
	 */
	@Override
	public void setController(ControllerIF cif) {
		executionPanelController = (ExecutionPanelController) cif;
	}

	/**
	 * Set the ok button editability according to a given parameter
	 * @param bool boolean
	 */
	public void setPanelEditable(boolean bool) {
		okButton.setEnabled(bool);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource().equals(okButton)) {
			executionPanelController.action();
		}
	}
	
	public Long getTicketId() {
		return ticket.getTicket_id();
	}

}
